using Rougamo;
using Rougamo.Context;

namespace JGSY.Rougamo.AOP
{
    public class LoggingAttribute : MoAttribute
    {
        public override void OnEntry(MethodContext context)
        {
            Console.WriteLine($"[日志] 进入方法: {context.Method.DeclaringType?.FullName}.{context.Method.Name}");
            Console.WriteLine($"[日志] 参数: {string.Join(", ", context.Arguments?.Select(p => p?.ToString() ?? "null") ?? Array.Empty<string>())}");
        }

        public override void OnSuccess(MethodContext context)
        {
            Console.WriteLine($"[日志] 方法成功返回: {context.Method.DeclaringType?.FullName}.{context.Method.Name}");
            Console.WriteLine($"[日志] 返回值: {context.ReturnValue?.ToString() ?? "null"}");
        }

        public override void OnException(MethodContext context)
        {
            Console.WriteLine($"[日志] 方法抛出异常: {context.Method.DeclaringType?.FullName}.{context.Method.Name}");
            Console.WriteLine($"[日志] 异常信息: {context.Exception}");
        }

        public override void OnExit(MethodContext context)
        {
            Console.WriteLine($"[日志] 退出方法: {context.Method.DeclaringType?.FullName}.{context.Method.Name}");
        }
    }
}    